%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Build a circle at a distance dr of object i
%
% inputs:
% contours   list of all contours
% i          index of the contour
% kh         Helmholtz parameter.
% ppl        required number of points per wavelength on the circle
% dr         minimum distance between the circle and the contour
%
% outputs:
% D          circle
% h_D        point spacing on D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [D,h_D] = get_circle(contours,i,kh,ppl,dr)

C        = contours{i};

xc       = mean(C(1,:));
yc       = mean(C(4,:));
R        = max(sqrt((C(1,:) - xc).^2 + (C(4,:) - yc).^2 ));

% Target distance between discretization points
h_resok  = 2*pi/kh / ppl;
M        = ceil(2*pi*(R+dr) / h_resok);
M        = max(200,M);

theta    = linspace(0,2*pi,M);
D        = zeros(2,M);
RR       = R + dr;
D(1,:)   = xc + RR*cos(theta);
D(2,:)   = yc + RR*sin(theta);

fprintf(1,'\n# of pts on the outer contour : %d \n',M);

h_D      = 2*pi*RR/M;

return